Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following two functions.void fun... Start Learning for Free
Consider the following two functions.
void fun1(int n) {
if(n == 0) return;    
printf("%d", n);    
fun2(n - 2);    
printf("%d", n);
}
void fun2(int n) {
if(n == 0) return;    
printf("%d", n);    
fun1(++n);    
printf("%d", n);
}
The output printed when fun1 (5) is called is
  • a)
    53423122233445
  • b)
    53423120112233
  • c)
    53423122132435
  • d)
    53423120213243
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Consider the following two functions.void fun1(int n) {if(n == 0) retu...
  • Unroll recursion up to a point where we can distinguish the given options and choose the correct one!
  • Options B and D are eliminated.
  • A is the answer.
View all questions of this test
Most Upvoted Answer
Consider the following two functions.void fun1(int n) {if(n == 0) retu...
Explanation:

The given code consists of two functions fun1 and fun2. The function fun1 takes an integer argument n and calls the function fun2 with n-2 as an argument. It then prints the value of n and returns. The function fun2 takes an integer argument n and calls the function fun1 with n as an argument. It then prints the value of n and returns.

When fun1(5) is called, it follows the below steps:

1. fun1(5) calls fun2(3) as n-2=5-2=3
2. fun2(3) calls fun1(3)
3. fun1(3) calls fun2(1) as n-2=3-2=1
4. fun2(1) calls fun1(1)
5. fun1(1) calls fun2(-1) as n-2=1-2=-1
6. fun2(-1) returns as n==0
7. fun1(1) prints 1
8. fun1(1) returns
9. fun2(1) prints 1
10. fun2(1) returns
11. fun1(3) prints 3
12. fun1(3) returns
13. fun2(3) prints 3
14. fun2(3) returns
15. fun1(5) prints 5

Hence, the output printed when fun1(5) is called is 53423122233445.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer?
Question Description
Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer?.
Solutions for Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer?, a detailed solution for Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following two functions.void fun1(int n) {if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n);}void fun2(int n) {if(n == 0) return; printf("%d", n); fun1(++n); printf("%d", n);}The output printed when fun1 (5) is called isa)53423122233445b)53423120112233c)53423122132435d)53423120213243Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev